package com.xkdx.guangguang.fragment.city;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;

public class CityModule extends AbsModule {
	public List<Map<String, String>> cityList;
	JSONArray resultArray;
	JSONObject jsonObj;

	@Override
	public void parseData() throws Exception {
		resultArray = (JSONArray) result;
		for (int i = 0; i < resultArray.length(); i++) {
			jsonObj = (JSONObject) resultArray.get(i);
			String sortOfAct = jsonObj.getString("Act");
			if (sortOfAct.equals("getCityList")) {
				cityList = parseCityList(jsonObj.getJSONObject("Content"));
			}
		}
	}

	private List<Map<String, String>> parseCityList(JSONObject person) throws Exception{

		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		try {
			JSONObject stut = (JSONObject) person.get("Result");
			JSONArray ListInfo = (JSONArray) stut.getJSONArray("ListInfo");

			for (int i = 0; i < ListInfo.length(); i++) {
				JSONObject jsonObj = ((JSONObject) ListInfo.opt(i));
				Map<String, String> map = new HashMap<String, String>();
				map.put("CityID", jsonObj.getString("CityID"));
				map.put("CityName", jsonObj.getString("CityName"));
				list.add(map);
			}

		} catch (Exception e) {
			throw e;
		}
		return list;
	}

}
